package com.hzdh.account.controller.account;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzdh.account.response.account.ToDayBookResponse;
import com.hzdh.account.service.AccountService;

@Controller
@RequestMapping("/account")
public class AccountDetailController {

	private static Logger logger = LoggerFactory.getLogger(AccountDetailController.class); 
	
	@Autowired
	private AccountService accountService;
	
	
	@RequestMapping("/detail")
	public String detail(Long pkid, HttpServletRequest request) {
		
		ToDayBookResponse dayBookResponse = accountService.getToDayBookById(pkid);
		if (dayBookResponse != null) {
			List<ToDayBookResponse> dayBookResponses = accountService.getToDayBookByPayCode(dayBookResponse.getPayCode());
			request.setAttribute("dayBooks", dayBookResponses);
		}
		
		request.setAttribute("dayBook", dayBookResponse);
		
		return "account/accountDetail";
	}
	
	
	@ResponseBody
	@RequestMapping("/query/daybook")
	public Object queryDayBook(String payCode) {
		
		return accountService.getToDayBookByPayCode(payCode);
	}
}
